package com.csii.activiti.server.api;

import com.csii.activiti.server.api.vo.Result;
import com.csii.activiti.server.core.entity.db.ActFlowGroupEntity;
import com.csii.activiti.server.core.service.FlowGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="分组接口")
@RestController
@RequestMapping("/${activity.basic.url:activiti}/flow/group")
public class FlowGroupController {

    @Autowired
    private FlowGroupService flowGroupService;


    @ApiOperation("查询全部分组")
    @GetMapping("/queryActFlowGroupList")
    public Result<List<ActFlowGroupEntity>> queryActFlowGroupList(){
        return Result.ok(flowGroupService.queryActFlowGroupList());
    }

    @ApiOperation("编辑分组")
    @PostMapping("/editActFlowGroup")
    public Result editActFlowGroup(@RequestBody ActFlowGroupEntity actFlowGroup){
        flowGroupService.editActFlowGroup(actFlowGroup);
        return Result.ok();
    }

    @ApiOperation("删除分组")
    @PostMapping("/deleteActFlowGroup")
    public Result deleteActFlowGroup(@ApiParam("主键") @RequestParam("id") String id){
        flowGroupService.deleteActFlowGroup(id);
        return Result.ok();
    }

    @ApiOperation("添加分组")
    @PostMapping("/addActFlowGroup")
    public Result addActFlowGroup(@RequestBody ActFlowGroupEntity actFlowGroup){
        String id = flowGroupService.addActFlowGroup(actFlowGroup);
        return Result.ok((Object)id);
    }

    @ApiOperation("分组排序")
    @PostMapping("/batchUpdateSort")
    public Result batchUpdateSort(@ApiParam("有顺序的主键")@RequestBody List<String> ids){
        flowGroupService.batchUpdateSort(ids);
        return Result.ok();
    }

}
